package com.example.pageexample.database;

import androidx.paging.DataSource;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

import java.util.List;

@Dao
public interface PictureDao {
    @Query("SELECT * FROM Picture_Table")
    DataSource.Factory<Integer , Picture> getAll();//获得全部数据

    @Query("SELECT * FROM Picture_Table LIMIT :startPosition ,:count")
    List<Picture> getData(int startPosition , int count);//获得部分数据

    @Query("SELECT * FROM Picture_Table")
    List<Picture> getAllPicture();//获得全部数据

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertAll(List<Picture> list);//插入列表

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insert(Picture picture);//插入单条数据

    @Delete
    void delete(Picture picture);//删除全部

    /**
     * 获取数据库总条数
     * @return
     */
    @Query("SELECT COUNT(*) FROM Picture_Table")
    int getCount();
}
